#include "PlayerUtility.h"
#include "PlayerUtilityPrivate.h"
#include <MdaAudioTonePlayer.h>
#include <eikmenup.h>
#include <QDebug>

CPlayerUtilityPrivate* CPlayerUtilityPrivate::NewL(const TDesC& aFileName ,PlayerUtility *wrapper)
{
    CPlayerUtilityPrivate* self = NewLC(aFileName, wrapper);
    CleanupStack::Pop(self);  
    return self;
}
 
CPlayerUtilityPrivate* CPlayerUtilityPrivate::NewLC(const TDesC& aFileName , PlayerUtility *wrapper)
{
    CPlayerUtilityPrivate* self = new (ELeave) CPlayerUtilityPrivate(wrapper);
    CleanupStack::PushL(self);
    self->ConstructL(aFileName);
    return self;
}
 
CPlayerUtilityPrivate::~CPlayerUtilityPrivate()
{
	if(iPlayUtility)
	{
		iPlayUtility->Stop();
		iPlayUtility->Close();
	}
 
    delete iPlayUtility;
}
 
CPlayerUtilityPrivate::CPlayerUtilityPrivate(PlayerUtility *wrapper):
        q_ptr( wrapper )
{
}
 
void CPlayerUtilityPrivate::ConstructL(const TDesC& aFileName)
{
    iPlayUtility = CMdaAudioPlayerUtility::NewFilePlayerL(aFileName, *this);
	iPlaying = iPrepared = EFalse;
}
 
void CPlayerUtilityPrivate::Play()
{
	iPlayUtility->Play();
	iPlaying = ETrue;
}
 
void CPlayerUtilityPrivate::Stop()
{
	iPlayUtility->Stop();
	iPlaying = EFalse;
}

void CPlayerUtilityPrivate::Pause()
{
        iPlayUtility->Pause();
        iPlaying = EFalse;
}
 
void CPlayerUtilityPrivate::MapcPlayComplete(TInt /*aError*/)
{
	iPlaying = EFalse;
}
 
void CPlayerUtilityPrivate::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
	if(aError == KErrNone)
	{
		iPrepared = ETrue;
//                iPlayUtility->SetVolume(volume);
//                iPlayUtility->Play();
	}
}

void CPlayerUtilityPrivate::SetVolume(int volume)
{
    iPlayUtility->SetVolume(volume);
}

TInt CPlayerUtilityPrivate::MaxVolume()
{
    return iPlayUtility->MaxVolume();
}

TInt CPlayerUtilityPrivate::GetVolume(TInt& aVolume)
{
    return iPlayUtility->GetVolume(aVolume);
}
